package com.robot.merchant.controller;

import com.alibaba.fastjson.JSON;
import com.robot.merchant.pojo.MerchantMember;
import com.robot.merchant.service.MerchantMemberService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺名下会员
 *
 * @author lin
 */
@RestController
@CrossOrigin
@RequestMapping("/merchantMember")
public class MerchantMemberJsonController {

    @Autowired
    private MerchantMemberService merchantMemberService;

    /**
     * 增加MerchantMember
     *
     * @param merchantMember
     */
    @RequestMapping(value = "third/addMerchantMemberByMerchantMember", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public void thirdAddMerchantMemberByMerchantMember(@RequestBody String merchantMember) {
        merchantMemberService.add(JSON.parseObject(merchantMember, MerchantMember.class));
    }

    /**
     * 修改MerchantMember
     *
     * @param merchantMember
     */
    @RequestMapping(value = "third/updateMerchantMemberByMerchantMember", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public void thirdUpdateMerchantMemberByMerchantMember(@RequestBody String merchantMember) {
        merchantMemberService.update(JSON.parseObject(merchantMember, MerchantMember.class));
    }

    /**
     * 删除MerchantMember
     *
     * @param id
     */
    @RequestMapping(value = "third/deleteMerchantMemberById/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public void thirdDeleteMerchantMemberById(@PathVariable String id) {
        merchantMemberService.deleteById(id);
    }

    /**
     * 通过storeId和memberId查找店铺名下的某一会员
     *
     * @param storeId
     * @param memberId
     * @return
     */
    @RequestMapping(value = "third/findMerchantMemberByStoreIdAndMemberId/{storeId}/{memberId}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String thirdFindMerchantMemberByStoreIdAndMemberId(@PathVariable String storeId, @PathVariable String memberId) {
        return JSON.toJSONString(merchantMemberService.findByStoreIdAndMemberId(storeId, memberId));
    }
}
